import Vue from 'vue'
import VueRouter from 'vue-router'
import Community from '@/views/community'
import Layout from '@/views/Layout'
import store from '@/store/index.js'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Layout,
    children: [{
      path: '',
      redirect:  '/district'
    }, {
      path: '/district',
      name: 'District',
      component: () => import('@/views/district/index.vue'),
      meta: {
        title: '汉阳区数字房管综合管理平台'
      }
    }, {
      path: '/community',
      name: 'Community',
      component: Community,
      meta: {
        title: '汉阳区数字红色物业管理平台'
      }
    }, {
      path: '/property',
      name: 'Property',
      component: () => import('@/views/property/index'),
      meta: {
        title: '汉阳区数字红色物业管理平台'
      }
    }]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  to.meta && to.meta.title && store.commit('SET_TITLE', to.meta.title)
  setTimeout(() => {
    next()
  }, 100)
  next()
})

export default router
